bpo-43574: Dont overallocate list literals#24954
Closed
chadnetzer wants to merge 11 commits intopython:mainfrom
Closed
bpo-43574: Dont overallocate list literals#24954chadnetzer wants to merge 11 commits intopython:mainfrom
chadnetzer wants to merge 11 commits intopython:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before v3.9, list literals weren't over-allocated, but this behavior regressed starting with v3.9:
Switched to initializing list literals w/ LIST_EXTEND
https://bugs.python.org/issue39320
#17984
Commit where over-allocation of list literals first appeared
https://bugs.python.org/issue38328
#17114
6dd9b64
This changes to the original behavior of not over-allocating lists for list literals, by not over-allocating any 0-length list that is extended. Technically this is a change in behavior, as lists that are initialized to length 0, and then immediately extended, will not be over-allocated on that initial extension. This change in behavior is likely innocuous, and possibly desirable, whereas the long-standing Python behavior of not using over-allocation for list literals is almost certainly desired.
Adds a test_overallocation test for lists to find regressions (assuming the regression doesn't alter the behavior of both the list-literal and list-initialization from a known length).
https://bugs.python.org/issue43574